package com.in.mobilerechargedth;

import java.util.List;


import com.in.mobilerechargedth.api.ContactDetailApi;
import com.in.mobilerechargedth.constant.ConstantVariables;
import com.in.mobilerechargedth.model.ContactMoreDetailModel;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;

import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class FifthMoreDetailScreenActivity extends BaseActivity {

    TextView tvMoreDetail;
    Button backbtn;
    int operatorId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fifth_contact_more_detail_screen);

        String strOperatorId = getIntent().getStringExtra(ConstantVariables.OPERATOR_ID);
        operatorId = Integer.parseInt(strOperatorId);
        tvMoreDetail =(TextView) findViewById(R.id.tvMoreDetail);

        backbtn = (Button) findViewById(R.id.backbtn);
        backbtn.setVisibility(View.VISIBLE);
        backbtn.setOnClickListener(this);

        new ContactDetailTask().execute(new String [] {});
        setupAdmob();
        share();
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
    }
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        super.onClick(v);
        switch (v.getId()) {
        case R.id.backbtn:
            this.onBackPressed();
            break;
        }
    }


    /**
     * Async Task to proceed Operator.
     */
    private class ContactDetailTask extends AsyncTask<String, Void, List<ContactMoreDetailModel>> {

        private ProgressDialog mProgress;


        @Override
        protected void onPreExecute() {
            mProgress = new ProgressDialog(FifthMoreDetailScreenActivity.this);
            mProgress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            mProgress.setMessage("Loading...");
            mProgress.setCanceledOnTouchOutside(false);
            // Check press back key when showing dialog.
            mProgress.setOnKeyListener(new DialogInterface.OnKeyListener() {

                @Override
                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                    // TODO Auto-generated method stub
                    if (keyCode == KeyEvent.KEYCODE_BACK) {
                        return true;
                    }
                    return false;
                }
            });
            mProgress.show();

            super.onPreExecute();
        }

        @Override
        protected List<ContactMoreDetailModel> doInBackground(String... params) {
            ContactDetailApi api = new ContactDetailApi();
            List<ContactMoreDetailModel> data = null;
            try {
                data = api.getContactDetail(operatorId);
            } catch (Exception e) {
                Log.e("Exception", e.getMessage());
            }

            return data;
        }

        @Override
        protected void onPostExecute(List<ContactMoreDetailModel> result) {
            super.onPostExecute(result);

            if (result != null && result.size() > 0) {
                tvMoreDetail.setText(result.get(0).getDetail());
            }
            if (mProgress != null) {
                mProgress.dismiss();
                mProgress = null;
            }

        }

    }
}
